package com.IntelligentCommunity.community.service.impl;

import com.IntelligentCommunity.community.domain.RealDoor;
import com.IntelligentCommunity.community.service.IRealDoorService;
import com.IntelligentCommunity.es.api.RemoteEsMatchingDataService;
import com.IntelligentCommunity.es.domain.vo.EsDocInsertVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @Author：ZHP
 * @Package：com.IntelligentCommunity.community.service.impl
 * @Project：IntelligentCommunity
 * @name：IRealDoorServiceImpl
 * @Date：2024/8/1 11:23
 * @Filename：IRealDoorServiceImpl
 */
@Service
public class IRealDoorServiceImpl implements IRealDoorService {
    @Autowired
    private RemoteEsMatchingDataService remoteEsMatchingDataService;

    @Override
    public void add(RealDoor door) {
        if (door == null){
            throw new RuntimeException("参数不能为空");
        }
        ArrayList<EsDocInsertVo> esDocInsertVos = new ArrayList<>();
        EsDocInsertVo esDocInsertVo = new EsDocInsertVo();
        esDocInsertVo.setData(new HashMap<String,Object>(){{
            put("door",door);
        }});
        // 设置索引名称
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        // 获取当前日期
        String format = sdf.format(new Date());
        // 设置索引名称
        esDocInsertVo.setIndexName("door" + format);
        System.out.println(esDocInsertVo.getIndexName());
        esDocInsertVo.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        esDocInsertVos.add(esDocInsertVo);
        remoteEsMatchingDataService.insertCaptureData(esDocInsertVos);
    }
}
